home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / os utilities / testvm / testgestalt.c next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  2.0 KB  |  95 lines

  1. /*
  2.     File:        TestGestalt.c
  3.  
  4.     Contains:    
  5.  
  6.     Written by:     
  7.  
  8.     Copyright:    Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 7/23/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23. #ifndef __CTYPE__
  24. #include <CType.h>
  25. #endif
  26.  
  27. #ifndef __OSUTILS__
  28. #include <OSUtils.h>
  29. #endif
  30.  
  31. #ifndef __STDIO__
  32. #include <StdIO.h>
  33. #endif
  34.  
  35. #ifndef __GESTALTEQU__
  36. #include <GestaltEqu.h>
  37. #endif
  38.  
  39. #ifndef __TYPES__
  40. #include <Types.h>
  41. #endif
  42.  
  43. #include <Traps.h>
  44.  
  45. #define    TRUE            0xFF
  46. #define    FALSE            0
  47.  
  48. Boolean TrapAvailable(short theTrap);
  49.  
  50.  
  51. // check to see if a given trap is implemented. We follow IM VI-3-8.
  52. Boolean TrapAvailable(short theTrap)
  53. {
  54.     TrapType theTrapType;
  55.     short numToolboxTraps;
  56.     
  57.     if ((theTrap & 0x0800) > 0)
  58.         theTrapType = ToolTrap;
  59.     else
  60.         theTrapType = OSTrap;
  61.  
  62.     if (theTrapType == ToolTrap)
  63.     {
  64.         theTrap = theTrap & 0x07ff;
  65.         if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xaa6e, ToolTrap))
  66.             numToolboxTraps = 0x0200;
  67.         else
  68.             numToolboxTraps = 0x0400;
  69.         if (theTrap >= numToolboxTraps)
  70.             theTrap = _Unimplemented;
  71.     };
  72.  
  73.     return (NGetTrapAddress(theTrap, theTrapType) != NGetTrapAddress(_Unimplemented, ToolTrap));
  74. }
  75.  
  76.  
  77. void main()
  78. {
  79. OSErr        err;
  80. long        feature;
  81.  
  82. if (TrapAvailable(_Gestalt)) {
  83.     err = Gestalt(gestaltVMAttr, &feature);
  84.     if (!err) {
  85.         if (feature & 0x0001)
  86.             printf ("We have VM\n");
  87.         else
  88.             printf ("We don't have VM\n");
  89.         }
  90.     else 
  91.         printf ("Gestalt err = %i\n",err);
  92.     }
  93. else
  94.     printf ("No Gestalt\n");
  95. }